package com.team.arms.tijian.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.team.arms.tijian.entity.vo.RecommendVo;
import entity.Recommended;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 主检推荐复检表 Mapper 接口
 * </p>
 *
 * @author Huazige
 * @since 2022-06-02
 */
public interface RecommendedMapper extends BaseMapper<Recommended> {

    List<RecommendVo> selectrecommend();
    List<RecommendVo> selectrecommendbyname(@Param("field") String field, @Param("content") String content);

    List<RecommendVo> select(@Param("healthExaminStats") String healthExaminStats);
    List<RecommendVo> selectbyname(@Param("field") String field, @Param("content") String content,@Param("healthExaminStats") String healthExaminStats);

    @Select("SELECT IFNULL(MAX(CAST(bingyi_info_id AS UNSIGNED)),0) + 1 FROM b_bingyi_info")
    String getbingyiIdmax();

    @Select("SELECT IFNULL(MAX(CAST(bingyi_info_id AS UNSIGNED)),0) + 1 FROM b_bingyi_info")
    String getbingyiInfoIdmax();//b_bingyi_info

    @Select("SELECT IFNULL(MAX(CAST(family_id AS UNSIGNED)),0) + 1 FROM b_family_reigist_info")
    String getfamilyIdmax();

    //先插入两种表的数据 主键id 自增  ，然后在查询 ，其他表的外键插入查询的编号，保证数据的一致性
    @Insert({"insert into b_bingyi_info (name,sex,id_card,phone,bingyi_info_id) " +
            "VALUES (#{name},#{sex},#{id_card},#{phone},#{bingyiInfoId})"})
    boolean inser(@Param("name")String name,@Param("sex")String sex,@Param("id_card")String id_card,@Param("phone")String phone,@Param("bingyiInfoId")String bingyiInfoId);//b_bingyi_info

     @Insert({"insert into b_family_reigist_info (family_detail,family_id) " +
            "VALUES (#{familyDetail},#{familyId})"})
     boolean inserfamilyinfo(@Param("familyDetail")String familyDetail,@Param("familyId")String familyId);//b_family_reigist_info

    @Insert({"insert into b_bingyi_regist_info (year,bingyi_info_id,family_id,bingyi_id) " +
            "VALUES (#{year},#{bingyiInfoId},#{familyId},(SELECT IFNULL(MAX(CAST(bingyi_id AS UNSIGNED)),0) + 1 FROM b_bingyi_regist_info))"})

    boolean inserbingyiinfo(@Param("year")String year,@Param("bingyiInfoId")String bingyiInfoId,@Param("familyId")String familyId);//b_bingyi_regist_info

    @Insert({"insert into ti_sys_health_failed (examine_time,bingyi_info_id) " +
            "VALUES (#{examineTime},#{bingyiInfoId})"})
    boolean inserhealthfailed(@Param("examineTime")LocalDateTime examineTime, @Param("bingyiInfoId")String bingyiInfoId);//ti_sys_health_failed

    @Insert({"insert into ti_sys_health_examination (examine_id,health_examin_stats,bingyi_info_id) " +
            "VALUES (#{examineId},#{healthExaminStats},#{bingyiInfoId})"})
    boolean inserhealthexamination(@Param("examineId")String examineId,@Param("healthExaminStats")String healthExaminStats,@Param("bingyiInfoId")String bingyiInfoId);//ti_sys_health_examination
}
